package com.xy.order.service.impl;

import com.xy.order.anotation.MyAnotion;
import com.xy.order.entity.Course;
import com.xy.order.feign.StockFeign;
import com.xy.order.mapper.CourceMapper;
import com.xy.order.service.OrderService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.PostConstruct;


@Component
public class OrderServiceImpl implements OrderService, CommandLineRunner {


    @Autowired
    public CourceMapper courceMapper;

    @Autowired
    private StockFeign stockFeign;

    @Override
    public void run(String... args) throws Exception {
        System.out.println("初始化后 成功加载方法");
    }

    @Override
    public void test() {
        System.out.println("为了测试aop");
    }

    @GlobalTransactional(name = "orderTx",rollbackFor = RuntimeException.class)
    public String saveOrder() {
        Course c = new Course();
        c.setCname("order");
        c.setUserId(Long.valueOf(1));
        c.setCstatus("1");
        courceMapper.insert(c);

        stockFeign.saveStockList();
        return "order ds_test success";
    }


}
